package com.ddw.meedeeuh.shared.movie.database;

import java.util.Map;

public abstract class DBStreamDetailsFactory {

	public static DBStreamDetails create(int streamDetailsId, int movieId,
			Map<Integer, DBVideo> videos, Map<Integer, DBAudio> audios,
			Map<Integer, DBSubtitle> subtitles) {
		if(videos == null) {
			throw new IllegalArgumentException("The videos parameter cannot be null");
		}
		if(audios == null) {
			throw new IllegalArgumentException("The audios parameter cannot be null");
		}
		if(subtitles == null) {
			throw new IllegalArgumentException("The subtitles parameter cannot be null");
		}

		return new DBStreamDetailsImpl(streamDetailsId, movieId, videos, audios, subtitles);
	}

	private static class DBStreamDetailsImpl implements DBStreamDetails {

		private final int streamDetailsId;
		private final int movieId;
		private final Map<Integer, DBVideo> videos;
		private final Map<Integer, DBAudio> audios;
		private final Map<Integer, DBSubtitle> subtitles;

		public DBStreamDetailsImpl(int streamDetailsId, int movieId,
				Map<Integer, DBVideo> videos, Map<Integer, DBAudio> audios,
				Map<Integer, DBSubtitle> subtitles) {
			this.streamDetailsId = streamDetailsId;
			this.movieId = movieId;
			this.videos = videos;
			this.audios = audios;
			this.subtitles = subtitles;
		}

		@Override
		public Iterable<DBVideo> getVideos() {
			return this.videos.values();
		}

		@Override
		public Iterable<DBAudio> getAudios() {
			return this.audios.values();
		}

		@Override
		public Iterable<DBSubtitle> getSubtitles() {
			return this.subtitles.values();
		}

		@Override
		public int getStreamDetailsId() {
			return this.streamDetailsId;
		}

		@Override
		public int getMovieId() {
			return this.movieId;
		}

	}

}
